//
//  OrderViewController.swift
//  hunan_ios_ldnydfuz
//
//  Created by yzd on 2019/4/28.
//  Copyright © 2019 ldnsm. All rights reserved.
//

import UIKit
import LLCycleScrollView
class HomeViewController: UBaseViewController {
    private var bannerList =  [Banner]()
//    private var locationManager = AMapLocationManager()
//    var manager:CLLocationManager?
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationController?.isNavigationBarHidden = true
        getBanner()
        getUser()
  
        // Do any additional setup after loading the view.
    }
    var homeModel = HomeModel()
    var homeView = HomeView()
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        // 隐藏首页的导航栏 true 有动画
        self.navigationController?.setNavigationBarHidden(true, animated: false)
    }
    func getBanner()  {
        homeModel.getSwiper(by: ["":""], completion: {
            (result, message, data) in
            self.bannerList = data as! [Banner]
            self.homeView.bannerView.imagePaths = self.bannerList.filter { $0.image != nil }.map { $0.image! }
        })
    }
    func getUser() {
//        ApiProvider.request(UApi.getState(params: ["" : ""]), model: StateModel.self) { (returnData) in
//            if let data = returnData {
//                UserDefaults.standard.set(data.authStatus, forKey: String.authStatus)
//                UserDefaults.standard.set(data.serviceType, forKey: String.roleType)
//                 UserDefaults.standard.set(data.hasPwd, forKey: String.isPwd)
//            }
//        }
    }
    private func didSelectBanner(index: NSInteger) {
        let item = bannerList[index]
        let url = item.linkUrl
        if url!.count > 0 {
            let vc = UWebViewController(url: url)
            navigationController?.pushViewController(vc, animated: true)
        }
        
    }
    override func configUI() {
        
        homeView = HomeView(frame: CGRect(x: 0, y: 0, width: screenWidth, height: screenHeight))
        view.addSubview(homeView)
        homeView.enterBtn.addTarget(self, action: #selector(enter), for: .touchUpInside)
        homeView.bannerView.lldidSelectItemAtIndex = didSelectBanner(index:)
        let attestTouch = UITapGestureRecognizer(target: self, action: #selector(goAttest))
        homeView.attestView.addGestureRecognizer(attestTouch)
        homeView.attestView.isUserInteractionEnabled = true
//        let infoTouch = UITapGestureRecognizer(target: self, action: #selector(goInfo))
//        homeView.infoView.addGestureRecognizer(infoTouch)
//        homeView.infoView.isUserInteractionEnabled = true
    }
    @objc func goAttest(){
        let role =  UserDefaults.standard.integer(forKey: String.roleType)
        let state =  UserDefaults.standard.integer(forKey: String.authStatus)
            UIAlertController.showAlert(title: "温馨提醒", btnName: "我知道了", message: "入驻申请还未处理，请耐心等待")
    }
    @objc func enter(){
        let state =  UserDefaults.standard.integer(forKey: String.authStatus)
        if state == 2 {
            UIAlertController.showAlert(title: "入驻信息", btnName: "我知道了", message: "您已成功入驻，请勿重新提交入驻申请！")
        }else {
            UIAlertController.showAlert(title: "温馨提醒", btnName: "我知道了", message: "入驻申请还未处理，请耐心等待")
        }
    }
    func judgeState() {
      
    }
    //是否开启定位权限
    /*
     // MARK: - Navigation
     
     // In a storyboard-based application, you will often want to do a little preparation before navigation
     override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
     // Get the new view controller using segue.destination.
     // Pass the selected object to the new view controller.
     }
     */
    
}

